{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f1e77bfb",
   "metadata": {},
   "source": [
    "# week04 有序数据结构"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e7340f7b",
   "metadata": {},
   "source": [
    " ## 内容回顾：时间模块、range( )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "2e1ea21a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "3bbc3598",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2022, tm_mon=10, tm_mday=22, tm_hour=15, tm_min=22, tm_sec=58, tm_wday=5, tm_yday=295, tm_isdst=0)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "id": "06595c6a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world\n"
     ]
    }
   ],
   "source": [
    "#停顿的时间\n",
    "time.sleep(3)\n",
    "print(\"hello world\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "1d3fb707",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for i in range(5):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "faefa193",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,5):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "id": "aa266ae8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "数据获取……\n",
      "页面停留 12 秒\n",
      "下一页……\n",
      "数据获取……\n",
      "页面停留 12 秒\n",
      "下一页……\n",
      "数据获取……\n",
      "页面停留 7 秒\n",
      "下一页……\n",
      "数据获取……\n",
      "页面停留 6 秒\n",
      "下一页……\n",
      "数据获取……\n",
      "页面停留 10 秒\n",
      "下一页……\n"
     ]
    }
   ],
   "source": [
    "#实践：浏览抓取网页数据，模拟人的行为，让机器慢下来，每执行一次休息三秒钟。\n",
    "# 进阶：随机产生一个数（3,16），让程序停留随机的秒数\n",
    "import random\n",
    "for i in range(5):\n",
    "    print(\"数据获取……\")\n",
    "    wait_time = random.randint(3,12)\n",
    "    print(\"页面停留\",wait_time,\"秒\")\n",
    "    time.sleep(wait_time)\n",
    "    print(\"下一页……\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "b07045aa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当前是偶数秒\n",
      "hhh\n",
      "当前是偶数秒\n",
      "hhh\n",
      "当前是偶数秒\n",
      "hhh\n",
      "当前是偶数秒\n",
      "hhh\n",
      "当前是偶数秒\n",
      "hhh\n"
     ]
    }
   ],
   "source": [
    "#练习 课本P33页 涉及知识点：模块，变量，条件判断，\n",
    "\n",
    "import datetime\n",
    "import time,random\n",
    "\n",
    "odds = [ 1, 3,  5,  7,  9, 11,13,15,17,19,\n",
    "             21,23,25,27,29,31,33,35,37,39,\n",
    "             41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "for i in range(5):\n",
    "    right_this_seconds = datetime.datetime.today().second\n",
    "    if right_this_seconds in odds:\n",
    "        print(\"当前是奇数秒\")\n",
    "    else:\n",
    "        print(\"当前是偶数秒\")\n",
    "    wait_time = random.randint(1,5)\n",
    "    print(\"hhh\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "62b7f2ab",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9 bottles 在啤酒墙上~\n",
      "9 bottles 啤酒~\n",
      "拿下来一瓶给我吧\n",
      "啤酒被拿走一瓶了\n",
      "还剩下 8 bottles 在啤酒墙上~\n",
      "————\n",
      "8 bottles 在啤酒墙上~\n",
      "8 bottles 啤酒~\n",
      "拿下来一瓶给我吧\n",
      "啤酒被拿走一瓶了\n",
      "还剩下 7 bottles 在啤酒墙上~\n",
      "————\n",
      "7 bottles 在啤酒墙上~\n",
      "7 bottles 啤酒~\n",
      "拿下来一瓶给我吧\n",
      "啤酒被拿走一瓶了\n",
      "还剩下 6 bottles 在啤酒墙上~\n",
      "————\n",
      "6 bottles 在啤酒墙上~\n",
      "6 bottles 啤酒~\n",
      "拿下来一瓶给我吧\n",
      "啤酒被拿走一瓶了\n",
      "还剩下 5 bottles 在啤酒墙上~\n",
      "————\n",
      "5 bottles 在啤酒墙上~\n",
      "5 bottles 啤酒~\n",
      "拿下来一瓶给我吧\n",
      "啤酒被拿走一瓶了\n",
      "还剩下 4 bottles 在啤酒墙上~\n",
      "————\n",
      "4 bottles 在啤酒墙上~\n",
      "4 bottles 啤酒~\n",
      "拿下来一瓶给我吧\n",
      "啤酒被拿走一瓶了\n",
      "还剩下 3 bottles 在啤酒墙上~\n",
      "————\n",
      "3 bottles 在啤酒墙上~\n",
      "3 bottles 啤酒~\n",
      "拿下来一瓶给我吧\n",
      "啤酒被拿走一瓶了\n",
      "还剩下 2 bottles 在啤酒墙上~\n",
      "————\n",
      "2 bottles 在啤酒墙上~\n",
      "2 bottles 啤酒~\n",
      "拿下来一瓶给我吧\n",
      "啤酒被拿走一瓶了\n",
      "还剩下 1 bottles 在啤酒墙上~\n",
      "————\n",
      "1 bottles 在啤酒墙上~\n",
      "1 bottles 啤酒~\n",
      "拿下来一瓶给我吧\n",
      "啤酒被拿走一瓶了\n",
      "不能给你了，这瓶要放在墙上展示了\n",
      "————\n"
     ]
    }
   ],
   "source": [
    "#练习 课本P44页 涉及知识点：变量，条件判断，for循环\n",
    "beer_name = \"bottles\"\n",
    "\n",
    "for beer_num in range (9,0,-1):\n",
    "    print(beer_num,beer_name,\"在啤酒墙上~\")\n",
    "    print(beer_num,beer_name,\"啤酒~\")\n",
    "    print(\"拿下来一瓶给我吧\")\n",
    "    print(\"啤酒被拿走一瓶了\")\n",
    "    #情况一：只剩下一瓶的情况：\n",
    "    if beer_num == 1:\n",
    "        print(\"不能给你了，这瓶要放在墙上展示了\")\n",
    "#情况二：多余一瓶的情况：\n",
    "    else:\n",
    "        new_num = beer_num - 1\n",
    "        if new_num == 1 :\n",
    "            beer_name = \"bottles\"\n",
    "        print(\"还剩下\",new_num,beer_name,\"在啤酒墙上~\")\n",
    "    print(\"————\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bbf559af",
   "metadata": {},
   "source": [
    "# 有序的数据结构（）\n",
    ">1. 数值(本周)\n",
    "  >>  1 . int\n",
    "  >>  2 . float\n",
    "  >>  3 . complex\n",
    ">2. 字符串（本周）\n",
    "\n",
    ">3. 列表，元祖，字典，*集合（期中考核）P144前"
   ]
  },
  {
   "cell_type": "raw",
   "id": "72572451",
   "metadata": {},
   "source": [
    "数值的基本运算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "4bf0400f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2+2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "b6312c88",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4.5"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "18/4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "02c93b89",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "17//4#取整数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "da4cb610",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "17%5#取余数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "30370584",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "5**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "0ed97c3e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "## int(整数)\n",
    "a = 9\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "9e096067",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11.5 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "## float\n",
    "b = 11.5\n",
    "print(b,type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "53a30ccb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(5+3j) <class 'complex'>\n"
     ]
    }
   ],
   "source": [
    "## complex(虚数，复数)\n",
    "c = 5 + 3j\n",
    "print(c,type(c))"
   ]
  },
  {
   "cell_type": "raw",
   "id": "3226cc09",
   "metadata": {},
   "source": [
    "数值的一般方法（Mathods）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d6fc4aac",
   "metadata": {},
   "source": [
    "## 2. 字符串（string）\n",
    "> 1. 关于字符串的基本内容\n",
    "> 2. 关于字符串的方法及函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "6eaad07c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = \"Alex\"\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "dca81466",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = 'Alex'\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "18477489",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = '''Alex'''\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "a19b6426",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "c9fc096b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'doesn\\'t'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3aeffa4d",
   "metadata": {},
   "source": [
    "### 2.2 关于字符串的方法及函数\n",
    "> 1. 字符串的定义\n",
    ">> 1. Single quotes: 'allows embedded \"double\" quotes' 单引号:“允许嵌入双引号”\n",
    ">> 2. Double quotes: \"allows embedded 'single' quotes\" 双引号:\"允许嵌入'单'引号\"\n",
    ">> 3. Triple quoted: '''Three single quotes''', \"\"\"Three double quotes\"\"\" 三重引号:'''三个单引号''' \"\"\"三个双引号\"\"\"\n",
    "> 2. in 检查成员对象\n",
    "> 3. 字符串的拼接\n",
    "> 4. 字符串的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "1c43d660",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州南方学院坐落于广州市从化温泉镇\n"
     ]
    }
   ],
   "source": [
    "# 关于有序性\n",
    "title = \"广州南方学院坐落于广州市从化温泉镇\"\n",
    "print(title)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "bb0e9313",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[0]  # 取单一值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "bdf63d58",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'方'"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[3] # 取单一值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "10d3bf3d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'镇'"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "8df89982",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "17"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(title) # 检查文本的总长度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "33eae1bf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[0:6] # 取一定范围的值，这种方法我们称其为“切片”"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "39e62c6c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[:6] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "9347f3e2",
   "metadata": {},
   "outputs": [],
   "source": [
    "## enumerate 枚举，既可以获取到内容 item ，又可以获取到  索引值 index。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "id": "1d4451e9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 广\n",
      "1 州\n",
      "2 南\n",
      "3 方\n",
      "4 学\n",
      "5 院\n",
      "6 坐\n",
      "7 落\n",
      "8 于\n",
      "9 广\n",
      "10 州\n",
      "11 市\n",
      "12 从\n",
      "13 化\n",
      "14 温\n",
      "15 泉\n",
      "16 镇\n"
     ]
    }
   ],
   "source": [
    "## 利用for循环 遍历文本信息\n",
    "for c,w in enumerate(title):\n",
    "    print(c,w)  # c,w随意命名？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "a4c04c94",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 广\n",
      "广州这个词在这段文本中\n",
      "1 州\n",
      "2 南\n",
      "3 方\n",
      "4 学\n",
      "5 院\n",
      "6 坐\n",
      "7 落\n",
      "8 于\n",
      "9 广\n",
      "广州这个词在这段文本中\n",
      "10 州\n",
      "11 市\n",
      "12 从\n",
      "13 化\n",
      "14 温\n",
      "15 泉\n",
      "16 镇\n"
     ]
    }
   ],
   "source": [
    "# 思考，如何判断一段文本中是否存在“广州”，例如文本  title  中的内容,还可以确定其出现的次数\n",
    "for c,w in enumerate(title):\n",
    "    print(c,w)\n",
    "    if w == \"广\":\n",
    "        if title[c+1] == \"州\":  # c 和 w 的顺序倒过来\n",
    "            print(\"广州这个词在这段文本中\")  "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8f52ed42",
   "metadata": {},
   "source": [
    "2.2.2 in 检查成员对象 课本P59"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "eb5e7178",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## Page59   in 检查成员对象 \n",
    "\"南方\" in title"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bcef6ce6",
   "metadata": {},
   "source": [
    "2.2.3·字符串的拼接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "e5cec79f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好，Alex\n"
     ]
    }
   ],
   "source": [
    "print(\"你好\" + \"，\" + \"Alex\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "e97abd19",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "can only concatenate str (not \"int\") to str",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[0;32mIn [71]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[38;5;66;03m# 字符串不可以和 数字 进行连接，不然就这样\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m你好\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m1\u001b[39;49m \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAlex\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
      "\u001b[0;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str"
     ]
    }
   ],
   "source": [
    "# 字符串不可以和 数字 进行连接，不然就这样\n",
    "print(\"你好\" + 1 + \"Alex\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "e2a05500",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 <class 'int'>\n",
      "1 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "# 数值  与  字符串\n",
    "print(1,type(1))\n",
    "print(\"1\",type(\"1\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "74daef8d",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "unsupported operand type(s) for /: 'str' and 'str'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[0;32mIn [76]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[38;5;66;03m# 字符串不可以 用来运算，和数值混在一起也不行\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m3\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m2\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n",
      "\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for /: 'str' and 'str'"
     ]
    }
   ],
   "source": [
    "# 字符串不可以 用来运算，和数值混在一起也不行\n",
    "\"3\" / \"2\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "id": "f6ecf6ab",
   "metadata": {},
   "outputs": [],
   "source": [
    "width = 16\n",
    "heigt = 9\n",
    "面积 = width * heigt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "id": "232b4c1e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "144"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "面积"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "255f03e5",
   "metadata": {},
   "source": [
    "2.2.4 字符串的方法\n",
    "> 1. str.capitalize( ): 可以将首字母转成大写\n",
    "> 2. str.count( ): 数量\n",
    "> 3. str.split( )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "id": "4b5bbf6a",
   "metadata": {},
   "outputs": [],
   "source": [
    "name = \"derrick.rose is mvp\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "id": "0cc1b55f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Derrick.rose is mvp'"
      ]
     },
     "execution_count": 97,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.capitalize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "89e04c17",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 98,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.count(\"r\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "id": "672046dc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.count(\"新媒体\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "id": "7fca6b0d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['derrick.rose ', ' mvp']"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.split(\"is\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "id": "db7ad340",
   "metadata": {},
   "outputs": [],
   "source": [
    "text = 1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "504f742e",
   "metadata": {},
   "source": [
    "课后：预习第二章列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b69b95fa",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
